package com.tywj.lib.route

import android.app.Activity
import android.os.Bundle
import android.os.Parcelable
import androidx.fragment.app.Fragment
import java.io.Serializable

/**
 * <pre>
 *     author : June Yang
 *     time   : 2020/5/8
 *     desc   : 获取路由参数
 *     version: 1.0.0
 * </pre>
 */
class RouteParam : IRouteParam {

    private val param: IRouteParam

    constructor(activity: Activity) {
        param = ActivityRouteParam(activity.intent)
    }

    constructor(fragment: Fragment) {
        param = FragmentRouteParam(fragment.arguments ?: Bundle())
    }

    override fun getInt(key: String, defaultValue: Int): Int {
        return param.getInt(key, defaultValue)
    }

    override fun getLong(key: String, defaultValue: Long): Long {
        return param.getLong(key, defaultValue)
    }

    override fun getFloat(key: String, defaultValue: Float): Float {
        return param.getFloat(key, defaultValue)
    }

    override fun getDouble(key: String, defaultValue: Double): Double {
        return param.getDouble(key, defaultValue)
    }

    override fun getBoolean(key: String, defaultValue: Boolean): Boolean {
        return param.getBoolean(key, defaultValue)
    }

    override fun getString(key: String, defaultValue: String): String {
        return param.getString(key, defaultValue)
    }

    override fun <T : Serializable> getSerializable(key: String): T? {
        return param.getSerializable(key)
    }

    override fun <T : Parcelable> getParcelable(key: String): T? {
        return param.getParcelable(key)
    }

    override fun <T : Parcelable> getParcelableArrayList(key: String): ArrayList<T>? {
        return param.getParcelableArrayList(key)
    }
}